package com.cy.pj.user.controller;

import com.cy.pj.user.dao.UserDao;
import com.cy.pj.user.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {
    @Autowired
    UserDao userDao;

    @RequestMapping("/checkName")
    public String checkName(String name){

        List<String> nameList=userDao.checkUserName();

        return nameList.contains(name)?"用户名已存在":"";
    }


    @RequestMapping("/findAll")
    @CrossOrigin
    public List<User> findAll(){
       List<User> userList =userDao.findAll();
       for(User user:userList){
           System.out.println(user);
       }
       return userList;
    }
}
